package io.renren.modules.generator.controller;

import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;
import io.renren.controller.BaseController;
import io.renren.modules.generator.entity.EnterpriseMainEntity;
import io.renren.modules.generator.service.EnterpriseMainService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.Map;



/**
 * 企业基本信息
 *
 * @author chenshun
 * @email sunlightcs@gmail.com
 * @date 2020-09-20 15:38:09
 */
@RestController
@RequestMapping("generator/enterprisemain")
@Api("企业基本信息接口")
public class EnterpriseMainController extends BaseController {
    @Autowired
    private EnterpriseMainService enterpriseMainService;


    /**
     * 列表
     */
    @RequestMapping("/evaluate/list")
    @ApiOperation("企业评价分页列表")
    public R evaluateList(@RequestParam Map<String, Object> params,@RequestBody(required = false) EnterpriseMainEntity enterpriseMainEntity){
        PageUtils page = enterpriseMainService.queryEvaluateListPage(params,enterpriseMainEntity);

        return R.ok().put("page", page);
    }

    /**
     * 列表
     */
    @RequestMapping("/list")
    @ApiOperation("分页列表")
    public R list(@RequestParam Map<String, Object> params,@RequestBody(required = false) EnterpriseMainEntity enterpriseMainEntity){
        if (enterpriseMainEntity == null) {
            enterpriseMainEntity = new EnterpriseMainEntity();
        }
        enterpriseMainEntity.setDeptId(getDeptId());
        PageUtils page = enterpriseMainService.queryPage(params,enterpriseMainEntity);

        return R.ok().put("page", page);
    }

    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    @ApiOperation("根据id获取实体")
    public R info(@PathVariable("id") Integer id){
		EnterpriseMainEntity enterpriseMain = enterpriseMainService.getById(id);

        return R.ok().put("enterpriseMain", enterpriseMain);
    }

    /**
     * 信息
     */
    @RequestMapping("/infoByDeptid/{deptid}")
    @ApiOperation("根据id获取实体")
    public R infoByDeptid(@PathVariable("deptid") Integer deptid){
        EnterpriseMainEntity enterpriseMain = enterpriseMainService.getByDeptid(deptid);

        return R.ok().put("enterpriseMain", enterpriseMain);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @ApiOperation("保存")
    public R save(@RequestBody EnterpriseMainEntity enterpriseMain){
		enterpriseMainService.save(enterpriseMain);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @ApiOperation("更新")
    public R update(@RequestBody EnterpriseMainEntity enterpriseMain){
		enterpriseMainService.updateById(enterpriseMain);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @ApiOperation("删除")
    public R delete(@RequestBody Integer[] ids){
		enterpriseMainService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
